using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.POD;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_MailCell : UIBaseNode
    {
        #region Template Generate,don't modify
        protected partial class UIB_UIN_MailCell
        {
            #region ObjectBinding Generate
            public GameObject unread { protected set; get; }
            public IQIGame.Onigao.Framework.ExText unreadTitle { protected set; get; }
            public IQIGame.Onigao.Framework.ExText unreadSend { protected set; get; }
            public IQIGame.Onigao.Framework.ExText unreadTime { protected set; get; }
            public GameObject readed { protected set; get; }
            public IQIGame.Onigao.Framework.ExText readedTitle { protected set; get; }
            public IQIGame.Onigao.Framework.ExText readedTime { protected set; get; }
            public IQIGame.Onigao.Framework.ExText readedSend { protected set; get; }
            public GameObject mark { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("unread", out var __tbv0);
                this.unread = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("unreadTitle", out var __tbv1);
                this.unreadTitle = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("unreadSend", out var __tbv2);
                this.unreadSend = __tbv2;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("unreadTime", out var __tbv3);
                this.unreadTime = __tbv3;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("readed", out var __tbv4);
                this.readed = __tbv4;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("readedTitle", out var __tbv5);
                this.readedTitle = __tbv5;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("readedTime", out var __tbv6);
                this.readedTime = __tbv6;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("readedSend", out var __tbv7);
                this.readedSend = __tbv7;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("mark", out var __tbv8);
                this.mark = __tbv8;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify


        protected UIB_UIN_MailCell ui { get; set; }
        public MailSimplePOD mailSimplePOD { get; private set; }
        protected override void BeforeInit()
        {
            ui = new UIB_UIN_MailCell();
            ui.InitBinding(this.csObjBind);
        }
        protected override void OnInit()
        {

        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {
            this.mailSimplePOD = null;
        }
        public void Show(MailSimplePOD data)
        {
            this.Show();
            this.mailSimplePOD = data;
            var cfg = TableCenter.mail.Get(this.mailSimplePOD.cid);
            this.ui.readed.SetActive(this.mailSimplePOD.isRead);
            this.ui.unread.SetActive(!this.mailSimplePOD.isRead);
            this.ui.mark.SetActive(this.mailSimplePOD.canGetItem);
            string strSender = string.Format(cfg.Sender, this.mailSimplePOD.sender);
            string strTitle = string.Format(cfg.Title, this.mailSimplePOD.title);
            string strExpireTime = this.mailSimplePOD.expireTime == 0 ? string.Empty : string.Format(APIMail.ExpireTimeStr, APIUIConst.MillisSecondsToDH(GameServerModule.Instance.GetDiffTime(this.mailSimplePOD.expireTime)));
            if (!this.mailSimplePOD.isRead)
            {
                this.ui.unreadSend.text = strSender;
                this.ui.unreadTitle.text = strTitle;
                this.ui.unreadTime.text = strExpireTime;
            }
            this.ui.readedSend.text = strSender;
            this.ui.readedTitle.text = strTitle;
            this.ui.readedTime.text = strExpireTime;
        }
    }
}
